package devices

import (
	"context"
	v1 "devops-super/api/product/v1"
	"devops-super/internal/dao"
	"devops-super/internal/model/mymodel"
)

// GetAstLogs 获取设备AST日志
func (s *sDevice) GetAstLogs(ctx context.Context, req *v1.DeviceGetAstLogsReq) (res *v1.DeviceGetAstLogsRes, err error) {
	// 初始化响应结构体
	res = &v1.DeviceGetAstLogsRes{
		List: []*mymodel.IotDeviceAstLogResponse{},
	}

	// 查询数据库，获取指定设备的最近100条AST日志，按采样时间倒序排列
	var logs []*mymodel.IotDeviceAstLogResponse
	_ = dao.IotDeviceAstLog.Ctx(ctx).
		Where("device_no = ?", req.DeviceNo).
		Order("sampletime DESC").
		Limit(100).
		Scan(&logs)
	res.List = logs
	return
}
